package com.example.demo.mapper;

import com.example.demo.mapper.entity.Order;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-20 17:51
 */
@Mapper
@Repository
public interface StudentOrderMapper {
    @Insert("INSERT INTO `order` (order_number, student_id, commodity_id, status, points_used, notes, " +
            "province_id, city_id, area_id, address, contact_name, contact_phone) " +
            "VALUES (#{orderNumber}, #{studentId}, #{commodityId}, #{status}, #{pointsUsed}, #{notes}, " +
            "#{provinceId}, #{cityId}, #{areaId}, #{address}, #{contactName}, #{contactPhone}) ")
    @Options(useGeneratedKeys = true, keyProperty = "orderId", keyColumn = "order_id")
    void insertOrder(Order order);
    @Select("SELECT * FROM `order` WHERE status = #{status} AND student_id = #{studentId} AND canceled = 2")
    List<Order> selectStatusOrderList(@Param("studentId") int studentId, @Param("status") int status);
    @Select("SELECT * FROM `order` WHERE student_id = #{studentId} AND canceled = 1")
    List<Order> selectCanceledOrderList(int studentId);
    @Select("SELECT * FROM `order` WHERE order_id = #{orderId}")
    Order selectOrderById(int orderId);
    @Update("UPDATE `order` SET canceled = 1, cancel_reason = #{cancelReason}, cancel_date = #{cancelDate} WHERE order_id = #{orderId}")
    void updateCancelInfo(@Param("orderId")int orderId, @Param("cancelReason")int cancelReason, @Param("cancelDate")String cancelDate);
    @Update("UPDATE `order` SET status = #{status}, complete_date = #{completeDate} WHERE order_id = #{orderId}")
    void updateCompleteInfo(@Param("orderId")int orderId, @Param("status")int status, @Param("completeDate")String completeDate);
}
